package com.kaifamiao.convert;

import java.time.ZoneId;
import java.util.Date;
import java.util.TimeZone;

/**
 * 1、从 JDK 1.1 开始提供了 TimeZone 类来表示时区
 * 2、在 Java 8 之前使用 TimeZone 类的实例来表示时区
 */
public class TimeZoneTest {

	public static void main(String[] args) {
		
		TimeZone zone = TimeZone.getDefault();
		System.out.println( zone );
		
		zone = TimeZone.getTimeZone( "Asia/Shanghai" );
		System.out.println( zone );
		
		String[] zoneIds = TimeZone.getAvailableIDs();
		for( int i = 0 , n = zoneIds.length ; i < n ; i++ ) {
			String id = zoneIds[ i ];
			System.out.println( id );
		}
		
		ZoneId zoneId = ZoneId.of( "Asia/Harbin" );
		// java.time.ZoneId ==> java.util.TimeZone
		zone = TimeZone.getTimeZone( zoneId );
		System.out.println( zone );
		
		// java.util.TimeZone ===> java.time.ZoneId
		ZoneId zid = zone.toZoneId();
		System.out.println( zid );
		
		Date date = new Date();
		System.out.println( date );
		
		// 修改默认时区
		TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Monaco" ) );
		System.out.println( date );
	}

}
